import {Component, OnInit} from '@angular/core';
import {ArticleService} from "../../core/services/article.service";
import {FormControl} from '@angular/forms';
import {Router} from '@angular/router';

@Component({
    selector: 'app-rsidebar',
    templateUrl: './rsidebar.component.html',
    styleUrls: ['./rsidebar.component.scss']
})
export class RsidebarComponent implements OnInit {

    articleList:any;
    search:any;

    constructor(private articleService:ArticleService,
                private router:Router
                ) {
    }

    ngOnInit() {
        this.getArticleList();
    }

    /**
     * 文章列表
     */
    getArticleList() {
        this.articleService.getArticleList()
            .subscribe(data => {
                if (data.status_code == 200) {
                    this.articleList=data.result;
                    this.goToFirstArticle();
                }

            });
    }

    //跳转到第一篇文章
    goToFirstArticle(){
        var id=this.articleList[0].id;
        if (this.router.url == '/') {
            //根目录才跳转
            this.router.navigate(['/article',id]);
        }
    }

}
